package com.dissertation.compoent;

import com.alibaba.fastjson.JSON;
import com.dissertation.utils.AuthUtil;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * 记录执行数据库日志
 */
@Component
@Aspect
public class LogDB {

    private Logger logger = LoggerFactory.getLogger( getClass() );

    @Before( "execution(* com.dissertation.service.impl.SaveAssetsImpl.*(..))" )
    void log( JoinPoint joinPoint ) {
        String methodName = joinPoint.getSignature().getName();
        String methodArgs = JSON.toJSONString( joinPoint.getArgs() );
        String username = AuthUtil.getUsername();
        String id = AuthUtil.getId();
        logger.info( String.format( "[id=%-16s, username=%11s] %s(%s)", id, username, methodName, methodArgs ) );
    }
}
